from threading import Lock


class Foo:
    def __init__(self):
        self.lock2 = Lock()
        self.lock3 = Lock()
        self.lock2.locked()
        self.lock3.locked()

    def first(self, printFirst: 'Callable[[], None]') -> None:
        # printFirst() outputs "first". Do not change or remove this line.
        printFirst()
        self.lock2.release()

    def second(self, printSecond: 'Callable[[], None]') -> None:
        # printSecond() outputs "second". Do not change or remove this line.
        self.lock2.locked()
        printSecond()
        self.lock3.release()

    def third(self, printThird: 'Callable[[], None]') -> None:
        # printThird() outputs "third". Do not change or remove this line.
        self.lock3.locked()
        printThird()

import time

class Foo:
    def __init__(self):
        self.flag = 1

    def first(self, printFirst: 'Callable[[], None]') -> None:
        # printFirst() outputs "first". Do not change or remove this line.
        printFirst()
        self.flag = 2

    def second(self, printSecond: 'Callable[[], None]') -> None:
        # printSecond() outputs "second". Do not change or remove this line.
        while self.flag != 2:
            time.sleep(0.001)
        printSecond()
        self.flag = 3

    def third(self, printThird: 'Callable[[], None]') -> None:
        while self.flag != 3:
            time.sleep(0.001)
        # printThird() outputs "third". Do not change or remove this line.
        printThird()
        self.flag = 1
